﻿// Copyright (c) BeiYinZhiNian (1031622947@qq.com). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: http://www.caviar.wang/ or https://gitee.com/Cherryblossoms/caviar.

using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using HandyControl.Controls;
using HandyControl.Data;
using Microsoft.Win32;
using TemplateGeneratorApp.Core;
using MessageBox = HandyControl.Controls.MessageBox;

namespace TemplateGeneratorApp
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();
            combo_ui.ItemsSource = new object[]
            {
                UIFramework.AntDesign.ToString(),
                UIFramework.TDesgin.ToString(),
                UIFramework.MasaBlazor.ToString(),
                UIFramework.BootStrapBlazor.ToString(),
            };
            combo_mode.ItemsSource = new object[]
            {
                BlazorMode.Hybrid.ToString(),
                BlazorMode.Wasm.ToString()
            };
        }

        private void Btn_Create_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txt_projectName.Text))
            {
                MessageBox.Error("请填写项目名称","错误");
                return;
            }

            if (combo_ui.SelectedIndex > 0)
            {
                MessageBox.Error("未支持的UI框架", "错误");
                return;
            }

            if (string.IsNullOrWhiteSpace(txt_path.Text))
            {
                MessageBox.Error("请选择项目路径", "错误");
                return;
            }

            try
            {
                ProjectManager.CopyProject(new ProjectInfo()
                {
                    Name = txt_projectName.Text,
                    Dest = txt_path.Text,
                    UIFramework = (UIFramework)combo_ui.SelectedIndex,
                    BlazorMode = (BlazorMode)combo_mode.SelectedIndex,
                });

                MessageBox.Success("生成完成", "成功");
            }
            catch (Exception ex)
            {
                MessageBox.Error(ex.Message, "错误");
            }

        }

        private void Btn_SelectFolder_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new System.Windows.Forms.FolderBrowserDialog();
            var result = dialog.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                txt_path.Text = dialog.SelectedPath;
            }
        }
    }
}
